package com.os.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
 * 
 * @author MWX
 *
 */
public class JdbcConUtilM {


	private final static String DBURL="jdbc:mysql://172.18.20.1:3306/ordersystem?user=root&password=123&useUnicode=true&characterEncoding=utf8";
	//private final static String DBURL="jdbc:mysql://localhost:3306/mydb1?user=root&password=19901201&useUnicode=true&characterEncoding=utf8";
	private final static String USERNAME="root";
	private final static String PASSWORD="123";
	private final static String DBDRIVER="com.mysql.jdbc.Driver";
	/**
	 * 创建jdbc的连接
	 * @return 返回链接对象
	 */
	public static Connection getCon(){
		Connection con=null;
		try {
			Class.forName(DBDRIVER);
			try {
				con=DriverManager.getConnection(DBURL, USERNAME, PASSWORD);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return con;
	} 
	/**
	 * 关闭连接和预处理对象
	 * @param pst 预处理对象
	 * @param con 连接对象
	 */
	public static void closePstAndCon(PreparedStatement pst,Connection con){
		if(pst!=null){
			try {
				pst.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(con!=null){
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
